﻿
using System;
using UnityEngine;

//控制技能的释放，
public class SkillCaster
{
    Creature _owner;
    private Action _skillLogicEndCallback;

    public bool IsCasting { get { return _castingSkill != null; } }

    private SkillLogicBase _castingSkill;
    internal void Init(Creature owner,Action skillEndCallback=null)
    {
        _owner = owner;
        _skillLogicEndCallback = skillEndCallback;
    }

    internal void CastSkill(SkillLogicBase skillLogic,Creature target)
    {
        _castingSkill = skillLogic;
        skillLogic.Start(target,onSkillLogicEnd);
        //skillLogic.Start(target);
    }

    private void onSkillLogicEnd()
    {
        _castingSkill = null;
        if (_skillLogicEndCallback != null) { _skillLogicEndCallback(); }
    }

    public void Loop()
    {
        //驱动正在释放的技能
        if (_castingSkill != null)
        {
            _castingSkill.Loop();
        }
    }
}
